﻿Imports System.IO

''' <summary>
'''SystemError
''' </summary>
Public Class SystemError
    'My.Application.Info.DirectoryPath + "\\"+
    Private Shared m_folderPath As String = New System.IO.DirectoryInfo(My.Application.Info.DirectoryPath).Parent.FullName + "\logs\"
    Private Shared m_fileName As String = "error_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"
    Public Shared strSpace As String = Space(3)

    Public Shared Property FolderPath() As [String]
        Get
            Return (m_folderPath)
        End Get
        Set(ByVal value As [String])
            If value IsNot Nothing OrElse value <> "" Then
                m_folderPath = value
            End If
        End Set
    End Property

    Public Shared Property FileName() As [String]
        Get
            Return (m_fileName)
        End Get
        Set(ByVal value As [String])
            If value IsNot Nothing OrElse value <> "" Then
                m_fileName = value
            End If
        End Set
    End Property
    Public Shared Sub SystemLog(ByVal ex As Exception)

        'Console.WriteLine("System Error: {0}", message)

        If Not System.IO.Directory.Exists(FolderPath) Then
            System.IO.Directory.CreateDirectory(FolderPath)
        End If
        Dim sr As New StreamWriter(FolderPath & FileName, True, System.Text.Encoding.UTF8)
        sr.WriteLine(DateTime.Now.ToString() & strSpace & ex.ToString)
        sr.Close()
        sr.Dispose()
    End Sub
    Public Shared Sub SystemLog(ByVal message As String, Optional msglDetail As String = "")

        'Console.WriteLine("System Error: {0}", message)

        If Not System.IO.Directory.Exists(FolderPath) Then
            System.IO.Directory.CreateDirectory(FolderPath)
        End If
        Dim sr As New StreamWriter(FolderPath & FileName, True, System.Text.Encoding.UTF8)
        sr.WriteLine(DateTime.Now.ToString() & strSpace & message)
        If String.IsNullOrEmpty(msglDetail) = False Then
            sr.WriteLine(strSpace & msglDetail)
        End If
        sr.Close()
        sr.Dispose()
    End Sub
End Class

